<template>
    <div class="login-box">
        <div class="lg-title">欢迎登录</div>
        <div class="login-form">
            <div class="login-cell">
                <img src="../assets/icon/user.png" />
                <input type="email" placeholder="请输入您的手机号" v-model="cellphone" />
            </div>
            <div class="login-cell">
                <img src="../assets/icon/password.png" />
                <input type="password" placeholder="请输入您的密码" v-model="password" />
            </div>
            <button class="login-cell login-cell-other login-cell-red" @click="login">登录</button>
            <button class="login-cell login-cell-other">微信登录</button>
            <button class="login-cell login-cell-other">支付宝登录</button>
        </div>
        <div class="forgets">
            <span>忘记密码？</span>
            <span>免费注册</span>
        </div>
    </div>
</template>
<style scoped>
    @import "../css/style.css";
    .login-box {
        position: fixed;
        background: #323542;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
    .lg-title {
        font-size: 1.25rem;
        line-height: 100px;
        color: #fff;
    }
    .login-form {
        padding: 1.25rem 1.875rem;
    }
    .login-cell {
        width: 100%;
        background-color: rgba(255, 255, 255, 0.1);
        height: 2.5rem;
        border-radius: 0.9375rem;
        margin-bottom: 1.25rem;
        text-align: left;
        display: flex;
    }
    .login-cell img {
        width: 1.25rem;
        height: 1.25rem;
        margin: 0.625rem;
    }
    .login-cell input {
        height: 2.5rem;
        padding: 0.375rem 1.6rem;
        background-color: transparent;
        font-size: 0.9375rem;
        color: #fff;
        box-sizing: border-box;
        outline: none;
    }
    .login-cell-other {
        border: 0.0625rem solid #9598a5;
        color: #9598a5;
        text-align: center;
        line-height: 2.5rem;
        display: block;
    }
    .login-cell-red {
        background-color: #e21323;
        color: #fff;
    }
    .forgets {
        color: #fff;
        opacity: 0.2;
        font-size: 0.875rem;
        display: flex;
        justify-content: space-around;
    }
</style>
<script>
    export default {
        data() {
            return {
                cellphone: "",
                password: "",
            }
        },
        methods: {
            to(page) {
                this.$router.push({
                    name: page
                })
            },
            login() {
                if (this.cellphone == "") {
                    this.$toast('请输入手机号');             
                    return
                }
                if (this.password == "") {
                    this.$toast('请输入密码');
                    return
                }
                this.$post('/user/login', {
                        cellpone: this.cellphone,
                        password: this.password
                    })
                    .then((response) => {
                        console.log(response)
                        if (response.status == 0) {
                            localStorage.setItem("token", response.data);
                            this.$toast('登录成功！');
                            this.to('user');
                        }
                    })
            }
        }
    }
</script>